package router

import (
	"gitee.com/freedom_feel/gui-bos-api/cmd/controllers"
	"gitee.com/freedom_feel/gui-bos-api/cmd/controllers/upload"
	"gitee.com/freedom_feel/gui-bos-api/cmd/middleware"
	"gitee.com/freedom_feel/gui-bos-api/global"
	"github.com/gin-gonic/gin"
)

//@title GUI-BOS API
//@version 1.0
//@description 前后端分离后的API文档
//
//@SecurityDefinitions.apikey Bearer
//@in header
//@name Authorization
//
//@host localhost:8080
//@BasePath /api/v1

// 静态页面
func InitStaticRouter(r *gin.Engine) {
	// 提供静态文件
	r.Static("/static", "./cmd/static")
	// 提供默认的静态页面
	r.GET("/", controllers.MallHome)
	r.GET("/shop", controllers.MallHome)
	//login
	{
		r.GET("/login_page", controllers.DefaultPage)
		r.GET("/register_page", controllers.RegDefaultPage)
		r.GET("/update/pwd_page", controllers.UpPwdDefaultPage)
	}

	r.GET("/userinfo", middleware.AuthMiddleware(), controllers.UserInfo)
	r.GET("/system/mall", middleware.AuthMiddleware(), controllers.SystemMall)
	//采集
	r.GET("/task/collect", middleware.AuthMiddleware(), controllers.TaskHome)
	// 提供静态文件(upload)
	r.Static("/mnt", "./mnt")
}

// 用户
func InitUserRouter(r *gin.Engine) {
	v1 := r.Group("/api/v1")
	v1.POST("/login", controllers.Login) //登录（首次注册）
	//管理注册
	v1.POST("/reg", controllers.Register) //注册
	//user:=r.Use(middleware.AuthMiddleware())
	//sendSms
	r.POST("/sendSms", controllers.SendSms)
	//userLogin
	r.POST("/login_mobile", controllers.MobileLogin)
	r.POST("/api/login/code", controllers.MobileLogin1)
	//UserPwdLogin
	r.POST("/login_up", controllers.UserPwdLogin)
	r.POST("/api/login/login_up", controllers.UserPwdLogin1)
	//register
	r.POST("/register", controllers.Register)
	r.POST("/api/register", controllers.Register1) //注册
	//updatePwd
	r.POST("/update/pwd", controllers.UpdatePwd)
	r.POST("/api/login/reset-pwd", controllers.UpdatePwd1)
	//api/check-login
	r.GET("/api/check-login", controllers.CheckLogin)
	//loginOut
	r.GET("/api/LoginOut", middleware.AuthMiddleware(), controllers.LoginOut)
	//UploadAvatar
	r.POST("/api/upload-avatar", middleware.AuthMiddleware(), controllers.UploadAvatar)
	//GetUserInfo
	r.GET("/api/welcome-info", middleware.AuthMiddleware(), controllers.GetUserInfo)
	//增加管理
	r.GET("/api/add-admin", middleware.AuthMiddleware(), controllers.AddAdmin)
	r.GET("/product/car", middleware.AuthMiddleware(), controllers.ProductCar)
}

// 任务
func InitTaskRouter(r *gin.Engine) {
	authGroup := r.Group("/auth", middleware.AuthMiddleware())
	{
		//获取数据
		authGroup.POST("/get/city/data", controllers.GetAreaData)
		//获取数据 （api 爬）
		authGroup.POST("/api/v1/city_work", controllers.GetCityData)
		//删除数据
		authGroup.POST("/delete/api/brand_name/data", controllers.DelBrandData)
		//查询任务
		authGroup.POST("/query/task/api", controllers.QueryTask)
		//创建任务
		authGroup.POST("/creat/task/api", controllers.GetCityData)
		//设置优先级
		authGroup.POST("/update/score/api", controllers.SetScore)
		//获取任务
		authGroup.POST("/get/task/api", controllers.GetTask)
		//结束任务
		authGroup.POST("/end/task/api", controllers.EndTask)
		//任务回调
		authGroup.POST("/notify/task/api", controllers.Notify)
		//添加地区 code
		authGroup.GET("/insert/area", controllers.InsertArea)
	}
}

func InitProductRouter(r *gin.Engine) {
	r.GET("/api/products", controllers.PdtList)
	r.GET("/api/categories", controllers.PdtCgyList)
	r.GET("/api/promotions", controllers.PdtHostList)
	//详情
	r.GET("/product", middleware.AuthMiddleware(), controllers.PdtDescription)
	r.GET("/get/product/desc", middleware.AuthMiddleware(), controllers.GetDtdDesc)
}

func InitUploadRouter(r *gin.Engine) {
	r.Static(global.StaticPath, global.SaveDir)
	up := r.Group("/api/v1")
	up.POST("/upload", upload.SmartUploadHandler)
}
